package com.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.reggie.DTO.OrdersDto;
import com.reggie.common.R;
import com.reggie.entity.OrderDetail;
import com.reggie.entity.Orders;
import com.reggie.service.OrderDetailService;
import com.reggie.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    @Autowired
    private OrderDetailService orderDetailService;
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
ordersService.submit(orders);
return R.success("下单成功");
    }
    @GetMapping("/userPage")
    public R<Page>getAPPOrder(int page,int pageSize) {
        //        构造分页器
        Page<OrderDetail> page1 = new Page<>(page, pageSize);
//        条件筛选器  用于设置查询顺序
        LambdaQueryWrapper<OrderDetail> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//        lambdaQueryWrapper.orderByDesc(OrderDetail::);
//        调用page
        orderDetailService.page(page1, lambdaQueryWrapper);
        return R.success(page1);
    }
    @GetMapping("/page")
    public R<Page>getOrder(int page,int pageSize) {
        //        构造分页器
        Page<OrderDetail> page1 = new Page<>(page, pageSize);
//        条件筛选器  用于设置查询顺序
        LambdaQueryWrapper<OrderDetail> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//        lambdaQueryWrapper.orderByDesc(OrderDetail::);
//        调用page
        orderDetailService.page(page1, lambdaQueryWrapper);
        return R.success(page1);
    }
}
